package org.huangrui.juc.day03;

/**
 * JUC --> day03
 * 缓存行分开
 * @author hr
 * @createTime 2022-04-04 10:03
 */
public class T04_CacheLinePadding {
    private static long COUNT = 1_0000_0000L;
    private static class Padding{
        private volatile long p1,p2,p3,p4,p5,p6,p7; //long 类型8个字节byte
    }
    private static class T extends Padding {
        private volatile long x = 0;
    }
    private static T[] arr = new T[2];
    static {
        arr[0] = new T();
        arr[1] = new T();
    }
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < COUNT; i++) {
                arr[0].x = i;
            }
        }, "input thread name");
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < COUNT; i++) {
                arr[1].x = i;
            }
        }, "input thread name");
        long start = System.nanoTime();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        long end = System.nanoTime();
        System.out.println((end - start) /100_0000);
    }
}
